﻿Imports System.Collections.Generic
Imports System.Data
Imports CondorTravel.BC
Imports CondorTravel.BE
Imports CondorTravelUTIL.DL

Public Class BuscarPaquete
    Inherits System.Web.UI.Page
    Dim itemgridview As GridViewRow
    Dim casilla As System.Web.UI.WebControls.CheckBox


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnConsultar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnConsultar.Click
        ListarPaquetes()
    End Sub

    Protected Sub btnSalir_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSalir.Click
        Response.Write("<script language=Javascript>window.close();</script>")
    End Sub

    Private Sub ListarPaquetes()

        Dim objPaqueteBE As New PaquetesBE
        Dim objUtil As New Funciones
        If IsNumeric(txtCodPaquete.Text.Trim) Then
            objPaqueteBE.codPaquete = Val(objUtil.ReemplazarTexto(txtCodPaquete.Text.Trim))
        Else
            objPaqueteBE.codPaquete = 0
        End If
        If txtNomPaquete.Text <> "" Then
            objPaqueteBE.NombrePaquete = objUtil.ReemplazarTexto(txtNomPaquete.Text.Trim)
        Else
            objPaqueteBE.NombrePaquete = ""
        End If
        Dim objPaquete As New PaquetesBC
        dtgPaquete.DataSource = objPaquete.ListaPaqueteBusq(objPaqueteBE)
        dtgPaquete.DataBind()
        If dtgPaquete.Rows.Count <= 0 Then
            dtgPaquete.Visible = False
            lblError.Visible = True
        Else
            dtgPaquete.Visible = True
            lblError.Visible = False
        End If
    End Sub


    Protected Sub btnSeleccionar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSeleccionar.Click
        Dim dt As New DataTable
        Dim scodigoPaquete As String = String.Empty
        Dim sNombrePaquete As String = String.Empty
        Dim scadena As String

        For Each Me.itemgridview In dtgPaquete.Rows
            casilla = itemgridview.FindControl("chkSeleccionar")

            If casilla.Checked = True Then
                scodigoPaquete = CType(itemgridview.FindControl("lblcodigoPaq"), Label).Text
                sNombrePaquete = CType(itemgridview.FindControl("lblNombrePaq"), Label).Text

            End If

        Next
        scadena = scodigoPaquete
        If scodigoPaquete.ToString.Trim = "" Then

            Session("BPCodigoPaquete") = ""
            Session("BPNombrePaquete") = ""
            Exit Sub
        End If
        Response.Write("<script language=Javascript>window.returnValue = " & scadena & ";</script>")
        Response.Write("<script language=Javascript>window.close();</script>")
        Session("BPCodigoPaquete") = scodigoPaquete
        Session("BPNombrePaquete") = sNombrePaquete

    End Sub
End Class